using Domain.Dto;
using Domain.Interface;
using Domain.Model;
using Gmmy.DomainExtension;
using Gmmy.Utility;
using Surging.Core.CPlatform.Ioc;
using System.Threading.Tasks;

namespace Domain.Services
{
    public class SampleModelDomainService : ServiceBase,ISampleModelDomainService
    {
        private readonly ISampleModelRepository _repository;

        public SampleModelDomainService(ISampleModelRepository repository)
        {
            this._repository = repository;
        }

		/// <summary>
        /// 创建案例模型
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task Create(SampleModelCreateInput input)
        {
            var model = new SampleModel(input);
			//todo:领域服务逻辑

            _repository.Add(model);
        }

        /// <summary>
        /// 更新案例模型
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task Update(SampleModelUpdateInput input)
        {
            //todo:领域服务逻辑
            var model = await _repository.GetByKeyAsync(input.ID);
            if (model == null)
            {
                throw new CustomException("所选案例模型不存在!");
            }

            model.Update(input);
            _repository.Update(model);
        }
    }
}
